/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tutwiz.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author vind
 */
@Entity
public class Step implements Serializable, Comparable<Step> {

    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable=false)
    private String title;
    @Column(nullable=false, length=1000)
    private String text;
    private String image;
    @Column(length=1000)
    private String code;
    private String link;
    private int stepOrder;
    
    @ManyToOne(optional=false)
    @JoinColumn(name="TUTORIAL_FK")
    private Tutorial tutorial;
    
    @OneToMany(mappedBy="step", cascade=CascadeType.ALL)
    private List<Comment> comments = new ArrayList<Comment>();

    public Step() {
    }

    public Step(Tutorial tutorial, int stepOrder, String title, String text) {
        this.tutorial = tutorial;
        this.stepOrder = stepOrder;
        this.title = title;
        this.text = text;
        this.image = null;
        this.link = null;
    }
    
    

    public Step(Tutorial tutorial, int stepOrder, String title, String text, String image, String link) {
        this.tutorial = tutorial;
        this.stepOrder = stepOrder;
        this.title = title;
        this.text = text;
        this.image = image;
        this.link = link;
    }
    
    public int getStepOrder() {
        return stepOrder;
    }
    
    public void setStepOrder(int stepOrder) {
        this.stepOrder = stepOrder;
    }

    public Long getId() {
        return id;
    }
    

    public Collection<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Step)) {
            return false;
        }
        Step other = (Step) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Step{" + "id=" + id + ", title=" + title + ", text=" + text + '}';
    }

    @Override
    public int compareTo(Step o) {
        return new Integer(this.stepOrder).compareTo(new Integer(o.stepOrder));
    }
}
